package sort.test327;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/19 12:41
 */
public class Solution1 {

    // 查柜动规求解
    public int countRangeSum(int[] nums, int lower, int upper) {
        int n = nums.length;
        int ans = 0;
        long[] dp = new long[n];
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (i == j) {
                    dp[j] = nums[i];
                } else {
                    dp[j] = nums[j] + dp[j - 1];
                }
                if (dp[j] >= lower && dp[j] <= upper) {
                    ans++;
                }
            }
        }
        return ans;
    }
}
